<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta name="renderer" content="ie-comp">
<html>
  <head>
	<title>字典信息</title>
	<%@ include file="/WEB-INF/jsp/include.jsp"%>
	<script type="text/javascript">
		 var path = "${path}";
         var codeFlag = 0;
         var nameFlag = 0;
		 $(function(){
			 setValue();
		  });
 
		 function setValue(){
			    var rows = parent.$('#tt').datagrid('getSelections');
			    var rowData = rows[0];
			    $("#dictId").val(rowData.dictId);
				$("#dictCode").val(rowData.dictCode);
				$("#dictName").val(rowData.dictName);
				$("#dictType").val(rowData.dictType);
				$("#dictDescription").val(rowData.dictDescription);
				$("#sortby").val(rowData.sortby);
				$("#parentDictId").val(rowData.parentDictId);
			}

         //code 查重复
         function checkRepeatCode(value){
             var params = new Object();
             var type=$("#dictType").val();
             params.dictCode = value;
             params.dictType = type;
             $.ajax({
                 type: "POST",
                 url: '${path}/system/dict/returnSingleDictDto',
                 dataType: "json",
                 data: params,
                 success: function callback(data){
                     if(data.code=="0001"){
                         codeFlag = 0;
                     }else{
                         codeFlag = 1;
                         $.messager.alert('操作提示','代码不可用','info',function(){
                             $('#dictCode')[0].focus();
                         });
                     }
                 },
                 error:function(){

                 }
             });
         }

         //name 查重复
         function checkRepeatName(value){
             var params = new Object();
             var type=$("#dictType").val();
             params.dictName = value;
             params.dictType = type;

             $.ajax({
                 type: "POST",
                 url: '${path}/system/dict/returnSingleDictDto',
                 dataType: "json",
                 data: params,
                 success: function callback(data){
                     if(data.code=="0001"){
                         nameFlag = 0;
                     }else{
                         nameFlag = 1;
                         $.messager.alert('操作提示','名称不可用','info',function(){
                             $('#dictName')[0].focus();
                         });
                     }
                 },
                 error:function(){

                 }
             });
         }

         //当上一级的code改变时，下级的type跟着变
		 function btnSubmitEdit(flag) {
             if(codeFlag == 1){
                 checkRepeatCode($('#dictCode').val());
                 return;
             }
             if(nameFlag == 1){
                 checkRepeatName($('#dictName').val());
                 return;
             }
             if (!validform("dictForm")) {
                 return;
             }
				$.ajax({
		 			type:"POST",
					url:path+'/system/dict/update',
					data: $('#jsForm').serialize(),
					dataType:"json",
					async: false,
					success:function(data){
						if(data.code != '0000'){
		     				alert('保存数据时发生错误：' + data.msg);
		     			} else {
		     				parent.refreshGrid();
		     				closeLayer();
		     				
		    			}
					},
					error: function() {
						alert('保存数据时发生错误！');
					}
				});
			}
		function btnCancelEdit(){
			closeLayer();
		}
	</script>
  </head>

  <body  style="margin:5px; padding:0px;" >
  <%@ include file="/WEB-INF/jsp/loading.jsp" %>
	<div class="easyui-layout" fit="true" >
		<div id="AddDlgDiv" align="center">
			<form id="jsForm" method="post" >
				<table  class="f_table" cellspacing="1" align="center" >
					<tr>
						<td align="right" class="s_bg" style="width:70px">编码：</td>
						<td class="s_bg" style="width: 200px;height:25px;"><input type="text" id="dictCode" name="dictCode" class="easyui-validatebox" onchange="checkRepeatCode(this.value);" data-options="required:true" style="width: 100%;height:100%;"/></td>
						<td align="right" class="s_bg" style="width:70px;display:none">上级代码：</td>
						<td class="s_bg" style="width: 200px;height:25px;display:none;"><input type="text" id="parentDictId" name="parentDictId" value="0" readonly="readonly" class="easyui-validatebox" data-options="required:true" style="width:100%;height:100%;"/></td>
						<td align="right" class="s_bg" style="width:70px">名称：</td>
						<td class="s_bg" style="width: 200px;height:25px;"><input type="text" id="dictName" name ="dictName" class="easyui-validatebox" onchange="checkRepeatName(this.value);" data-options="required:true,tipPosition:'left'" style="width:100%;height:100%;"/></td>
					</tr>
					<tr>
						<td align="right"  class="s_bg" style="width:70px">描述：</td>
						<td class="s_bg"  style="width: 200px;height:25px;"><input type="text" id="dictDescription" name="dictDescription" class="easyui-validatebox" data-options="required:true" style="width:100%;height:100%;"/></td>
						<td align="right" class="s_bg" style="width:70px">类型：</td>
						<td class="s_bg" style="width: 200px;height:25px;"><input type="text" id="dictType" name="dictType" readonly="readonly" class="easyui-validatebox" data-options="required:true,tipPosition:'left'" value="0" style="width:100%;height:100%;"/></td>
					</tr>
					<tr>
						<td align="right" class="s_bg" style="width:70px">排序：</td>
						<td class="s_bg" style="width: 200px;height:25px;"><input type="text" id="sortby" name="sortby" class="easyui-validatebox" data-options="required:true"  style="width: 100%;height:100%;"/></td>
						<td align="right" class="s_bg" style="width:70px"></td>
						<td class="s_bg" style="width: 200px;height:25px;"></td>
						<input type="hidden" id="delMark" name="delMark" value="0" />
						<input type="hidden" id="dictId"  name="dictId" value=""/>
					</tr>
				</table>
			</form>  
			  <div align="center" style="margin-top: 15px;">
		        	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="btnSubmitEdit()">确定</a>
		        	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="btnCancelEdit();">取消</a>
       		 </div>
		</div>
	</div>
</body>
</html>
